﻿using DevExpress.XtraBars;
using DevExpress.XtraBars.Alerter;
using DevExpress.XtraEditors;
using DevExpress.XtraNavBar;
using DevExpress.XtraTabbedMdi;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using Lamex.Common;
using Lamex.Core;
using Lamex.Interface;
using Lamex.Library;
using Lamex.Library.CommonClass;
using Lamex.Main;
using Lamex.Main.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lamex
{
    public partial class frmMainForm : frmBase, IMdiForm
    {
        
        IToolbarRegister _MdiToolbar = null;
        MenuStrip _moduleMenus = new MenuStrip();
        DataTable dtMenu = new DataTable();
        List<string> lst = new List<string>();
        string funcName = "";
        public MenuStrip MainMenu { get { return _moduleMenus; } set { _moduleMenus = value; } }
        frmModuleContainer _ModuleContainer = null;
        ModuleManager _ModuleManager = null;
        DevExpress.XtraEditors.ComboBoxEdit cbm = null;
        Lamex.Common.IniFile ini = new Common.IniFile(Application.StartupPath + "\\config\\CSFramework3.ini");
        int iLanguage = 0;
        public frmMainForm()
        {
            InitializeComponent();
            SkinTools.LoadSkinList(btnSetSkin);
            lookupEidt.EditValueChanged += new EventHandler(lookupEidt_EditValueChanged);
            comboxEdit.EditValueChanged += new EventHandler(comboxEdit_EditValueChanged);
            comboxEdit.KeyDown += new KeyEventHandler(comboxEdit_KeyDown);
            barEditItem2.EditValueChanged += new EventHandler(barEditItem8_EditValueChanged);
            navBarControl1.HideNavPaneForm();
            //lookupEidt.Enter += new EventHandler(lookupEidt_Enter);
            if (Loginer.CurrentUser.ChangeLanguage == 0)
            {
                lookupEidt.NullValuePrompt = "菜单搜索";
                comboxEdit.NullValuePrompt = "菜单搜索";
                barStaticDept.Caption = "部门：" + Lamex.Common.Loginer.CurrentUser.DeptName; 
                barStaticIUser.Caption = "用户：" + Lamex.Common.Loginer.CurrentUser.Account;
                barStaticEmail.Caption = "Email：" + Lamex.Common.Loginer.CurrentUser.Email;
                barStaticDb.Caption = "数据库：" + Lamex.Common.Loginer.CurrentUser.DBName;
                barStaticCopyRight.Caption = "© 东莞美时家具有限公司（HNI集团成员）版权所有";
                barSubRecordUse.Caption = "最近";
                btnSetSkin.Caption = "皮肤";
                barHelp.Caption = "帮助";
            }
            else
            {
                lookupEidt.NullValuePrompt = "Menu search";
                comboxEdit.NullValuePrompt = "Menu search";
                barStaticDept.Caption = "Dept：" + Lamex.Common.Loginer.CurrentUser.DeptName; 
                barStaticIUser.Caption = "User：" + Lamex.Common.Loginer.CurrentUser.Account;
                barStaticEmail.Caption = "Email：" + Lamex.Common.Loginer.CurrentUser.Email;
                barStaticDb.Caption = "Database：" + Lamex.Common.Loginer.CurrentUser.DBName;
                barStaticCopyRight.Caption = "© 2019 Dongguan Lamex Furniture Co. Ltd. (Member HNI Corp). All Rights Reserved.";
                barSubRecordUse.Caption = "MostRecentlyUsed";
                btnSetSkin.Caption = "Skin";
                barHelp.Caption = "Help";
            }
           // barSubRecordUse.Caption = "最近";
            
            //barStaticCh.ItemClick += new ItemClickEventHandler(batStaticCh_ItemClick);
            //barStaticEng.ItemClick += new ItemClickEventHandler(barStaticEng_ItemClick);
            barBtnCh.ItemClick += new ItemClickEventHandler(barBtnCh_ItemClick);
            barBtnEng.ItemClick += new ItemClickEventHandler(barBtnEng_ItemClick);
            barLanguageChange.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(barLanguageChange_ItemClick);
            
            iLanguage = Loginer.CurrentUser.ChangeLanguage;
            if (iLanguage == 0)
                iLanguage = 1;
            else
                iLanguage = 0;
        }
        private void barEditItem8_EditValueChanged(object sender, EventArgs e)
        {
            funcName = barEditItem2.EditValue.ToString();
            cbm.Focus();
            this.cbm.Select(this.cbm.Text.Length, 0);
        }
        private void comboxEdit_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {

                DevExpress.XtraEditors.ComboBoxEdit combox = sender as DevExpress.XtraEditors.ComboBoxEdit;
          
                if (combox.EditValue.ToString() != "")
                {
                    foreach (ToolStripMenuItem item in _moduleMenus.Items)
                    {
                        EnumItem(item, combox);
                    }
                }
                combox.Focus();
                //comBoxEdit_KeyDown(sender, e);
            }

        }
        private void comboxEdit_EditValueChanged(object sender, EventArgs e)
        {
            DevExpress.XtraEditors.ComboBoxEdit combox = sender as DevExpress.XtraEditors.ComboBoxEdit;
            cbm = sender as DevExpress.XtraEditors.ComboBoxEdit;
            
            combox.Properties.Items.Clear();
            if (combox.EditValue.ToString() != "")
            {
                List<string> _lst = new List<string>();

                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[^a-zA-Z\r\n]+");
                if (!reg.Match(combox.EditValue.ToString()).Success)
                {
                    //遍历ArrayList中的所有信息 
                    foreach (object obj in lst)
                    {
                        //获得各汉字拼音首字母缩写 
                        string strName = GetChineseSpell(obj.ToString()).ToLower();
                        string strTxtName = combox.EditValue.ToString().ToLower();
                        //根据拼音进行匹配
                        if (strName.Contains(strTxtName) && strName.Substring(0, strTxtName.Length) == strTxtName)
                        {
                            _lst.Add(obj.ToString());
                        }
                    }

                    combox.Properties.Items.AddRange(_lst);

                }
            }
            else
            {
                combox.Properties.Items.AddRange(lst);
            }
            //combox.Focus();//设置可编辑焦点 同上
            combox.ShowPopup();//使ComboxEditor展开
        }
        /// <summary>      
        /// 拼音检索   
        /// </summary>    
        /// <param name="strText"></param>    
        /// <returns></returns>        
        static public string GetChineseSpell(string strText)
        {
            int len = strText.Length;
            StringBuilder strBuilder = new StringBuilder();
            for (int i = 0; i < len; i++)
                strBuilder.Append(GetLetter(strText.Substring(i, 1)));
            return strBuilder.ToString();
        }

        /// <summary>
        /// 得到首字母
        /// </summary>
        /// <param name="strChar"></param>
        /// <returns></returns> 
        public static string GetLetter(string strChar)
        {
            byte[] byteLetters = Encoding.Default.GetBytes(strChar);
            if (byteLetters.Length > 1)
            {
                int first = (short)byteLetters[0];
                int second = (short)byteLetters[1];
                int code = (first << 8) + second;
                int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
                for (int i = 0; i < 26; i++)
                {
                    int max = 55290;
                    if (i != 25) max = areacode[i + 1];
                    if (areacode[i] <= code && code < max)
                        return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
                }
                return string.Empty;
            }
            else
                return strChar;
        }
        private void lookupEidt_EditValueChanged(object sender, EventArgs e)
        {
         
        }
        private void EnumItem(ToolStripMenuItem item, DevExpress.XtraEditors.ComboBoxEdit combo)
        {

            for (int i = 0; i < item.DropDownItems.Count; i++)
            {
                ToolStripMenuItem dropItem = item.DropDownItems[i] as ToolStripMenuItem;
                ToolStripItem dropItems = item.DropDownItems[i] as ToolStripItem;
                if (combo.EditValue.ToString() == "") continue;
                
                if (dropItems.Text == combo.EditValue.ToString())
                {
                    dropItems.PerformClick();
                }
                EnumItem(dropItem, combo);
            }
        }
        
        public void InitUserInterface(IMsg lblStatus)
        {
            this._MdiToolbar = new DevBarRegister(this, barMainmenu);
            this.RegisterMdiButton();
            this._ModuleContainer = (frmModuleContainer)MdiTools.OpenChildForm(this as IMdiForm, typeof(frmModuleContainer), null);
            this._ModuleContainer.InitButtons();
            _ModuleManager = new ModuleManager(this, _ModuleContainer.xtraTabControl1);
            _ModuleManager.LoadModulesNew(lblStatus, _moduleMenus);
            //SystemAuthentication.SetMenuAuthority(_moduleMenus);
            //_ModuleManager.SetModuleSecurity(_moduleMenus);
            _ModuleManager.CreateToolButtons(barTools, _moduleMenus);
            RecentlyUseRecord.LoadRecentlyRecordList(barSubRecordUse, _moduleMenus);
            #region"临时表菜单栏功能"
            dtMenu.Columns.Add("ID", typeof(string));
            dtMenu.Columns.Add("菜单选项", typeof(string));
            #endregion
            string picPath = Application.StartupPath + @"\image\MESBanner.jpg";
            PictureEdit pic = new PictureEdit();
            //int height=barTools


            //_moduleMenus.Click += new EventHandler _moduleMenus_Click ;

            #region"左则菜单"
            //TreeView treeView = new TreeView();
            //treeView.AfterSelect += (sender, e) =>
            //{
            //    string name = e.Node.Name as string;
            //    if (!string.IsNullOrEmpty(name))
            //    {
            //        //MessageBox.Show(name);
            //    }
            //};
            //treeView.Dock = DockStyle.Fill;
            ////treeView.ImageList = this.imageList;
            //treeView.ItemHeight = 30;//设置高度，显示更美观

            //NavBarGroupControlContainer container = new NavBarGroupControlContainer();
            //container.Size = new System.Drawing.Size(213, 412);
            //container.Controls.Add(treeView);
            //navBarControl1.Controls.Add(container);

            //加载图标
            //this.imageList.Images.Add(LoadIcon(firstInfo.Icon));
            //int index = this.imageList.Images.Count - 1;//最后一个序号


            //group.LargeImageIndex = index;
            //group.SmallImageIndex = index;

            //加载树型菜单
            foreach (ToolStripMenuItem item in _moduleMenus.Items)
            {
                //创建一级列表
                TreeView treeView = new TreeView();
                treeView.ImageList = imageList1;
                treeView.Dock = DockStyle.Fill;
                //treeView.ImageList = this.imageList;
                treeView.ItemHeight = 20;//设置高度，显示更美观
                treeView.NodeMouseClick += new TreeNodeMouseClickEventHandler (treeView_MouseClick);
                treeView.AfterSelect += new TreeViewEventHandler(treeView_AfterSelect);
                
                NavBarGroupControlContainer container = new NavBarGroupControlContainer();
               
                container.Size = new System.Drawing.Size(213, 412);
                container.Controls.Add(treeView);
                navBarControl.Controls.Add(container);

                //加载图标
                //this.imageList.Images.Add(LoadIcon(firstInfo.Icon));
                //int index = this.imageList.Images.Count - 1;//最后一个序号
                
                NavBarGroup group = new NavBarGroup();
                group.Caption = item.Text;
                group.Name = item.Name;
                group.ControlContainer = container;
                group.Expanded = false;
                group.GroupClientHeight = 410;
                group.GroupStyle = NavBarGroupStyle.ControlContainer;
                //group.LargeImageIndex = index;
                //group.SmallImageIndex = index;
                navBarControl.Groups.Add(group);

                //创建一级列表
                TreeNode pNode = new TreeNode();
                pNode.ImageIndex = 0;
                pNode.Text = item.Text;
                pNode.Tag = item.Name;

                //pNode.ImageIndex = index;
                //pNode.SelectedImageIndex = index;
                treeView.Nodes.Add(pNode);

                EnumEachItem(item, pNode);
                treeView.ShowLines = true;

                
            }


            #endregion

            lookupEidt.ValueMember = "ID";
            lookupEidt.DisplayMember = "菜单选项";
            lookupEidt.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ID"));
            lookupEidt.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("菜单选项"));
            lookupEidt.DataSource = dtMenu;

            //if (Loginer.CurrentUser.ChangeLanguage == 0)
            //    barBtnCh_ItemClick(null, null);
            //else
            //{
            //    barBtnEng_ItemClick(null, null);
            //}

        }
        private void EnumEachItem(ToolStripMenuItem item, TreeNode treeNode)
        {

            for (int i = 0; i < item.DropDownItems.Count; i++)
            {
                ToolStripMenuItem dropItem = item.DropDownItems[i] as ToolStripMenuItem;
                ToolStripItem dropItema = item.DropDownItems[i] as ToolStripItem;

                TreeNode subNode = new TreeNode();
                subNode.ImageIndex = 1;
                subNode.Text = dropItema.Text;
                subNode.Name = dropItema.Name;
                subNode.Tag = dropItema;
                DataRow dr = dtMenu.NewRow();
                dr["ID"] = dropItema.Name;
                dr["菜单选项"] = dropItema.Text;
                lst.Add(dropItema.Text);
                dtMenu.Rows.Add(dr);
                //subNode.
                treeNode.Nodes.Add(subNode);

                //ToolStripMenuItem subitem = item.DropDownItems[i] as ToolStripMenuItem;
                EnumEachItem(dropItem, subNode);
            }
        }

        public IToolbarRegister MdiToolbar { get { return _MdiToolbar; } set { _MdiToolbar = value; } }
        public void RegisterMdiButton()
        {
            this.MdiToolbar.RegisteButton(this.MdiButtons);
        }

        public IList MdiButtons
        {
            get
            {
                IList btn = new ArrayList();
                //btn.Add(this.MdiToolbar.CreateButton("btnHelp", "帮助", Globals.LoadBitmap("24_Help.ico"), new Size(57, 28), DoHelp));
                //btn.Add(this.MdiToolbar.CreateButton("btnAbout", "关于", Globals.LoadBitmap("24_Help.ico"), new Size(57, 28), DoAbout));
                return btn;
            }
        }

        /// <summary>
        /// MDI主窗体的观察者
        /// </summary>
        public IObserver[] MdiObservers
        {
            get
            {
                IObserver[] os = new IObserver[3];
                //os[0] = new ObserverCloseAllChild(this);
                return os;
            }
        }
        
        private void DoHelp(IButtonInfo sender)
        {
            //Lamex.SystemManager.Company info= new SystemManager.Company();
            //info.ShowDialog();
        }
        private void DoAbout(IButtonInfo sender)
        {
            MessageBox.Show("测试窗体");
        }
        /// <summary>
        /// 显示模块容器窗体
        /// </summary>
        public void ShowModuleContainerForm()
        {
            _ModuleContainer.Activate();
        }
        private void frmMainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
            GC.Collect();
            
        }
        /// <summary>
        /// TreeNode.Click事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void treeView_MouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Tag != null && e.Node.Tag is ToolStripItem)
                (e.Node.Tag as ToolStripItem).PerformClick();
            //if ((sender as TreeNode) != null)
            //{
            //    TreeNode node = (sender as TreeNode);
            //    if (node.Tag != null && node.Tag is ToolStripItem)
            //    {
            //        //node.Selected = true;
            //        (node.Tag as ToolStripItem).PerformClick();
            //    }
            //}
        }
        /// <summary>
        /// 当用户点击树结点
        /// </summary>
        private void OnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            //if (e.Node.Tag != null && e.Node.Tag is ToolStripItem)
            //    (e.Node.Tag as ToolStripItem).PerformClick();
        }
        private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //if (e.Node.Tag != null && e.Node.Tag is ToolStripItem)
            //    (e.Node.Tag as ToolStripItem).PerformClick();
        }
        private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {

        }

        private void barStaticDb_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void frmMainForm_Load(object sender, EventArgs e)
        {
            this.pictureBox1.SendToBack();
           // this.panelControl1.BackColor = Color.Transparent;//将Panel设为透明
            //this.barTools = this.pictureBox1;
            this.pictureBox1.BringToFront();//将panel放在前面
            this.pictureBox1.BorderStyle = BorderStyle.None;

            
        }
       
        private void barBtuModify_ItemClick(object sender, ItemClickEventArgs e)
        {
            Main.frmModify frm = new Main.frmModify(Loginer.CurrentUser.Account);
            frm.ShowDialog();
        }
        private void ChangeChLanguage(ToolStripMenuItem item)
        {
            DataRow dr = SystemAuthentication.UserMenu.Select("WinformId='" + item.Name + "'").FirstOrDefault();
            if (dr != null)
                item.Text = dr["Name"].ToString();
            foreach (ToolStripDropDownItem c in item.DropDownItems)
            {
                ToolStripMenuItem dropItem = c as ToolStripMenuItem;
                ToolStripItem dropItema = c as ToolStripItem;
                DataRow _dr = SystemAuthentication.UserMenu.Select("WinformId='" + dropItema.Name + "'").FirstOrDefault();
                if (_dr != null)
                    dropItem.Text = _dr["Name"].ToString();
                ChangeChLanguage(dropItem);
            }
            
        }
        private void ChangeEngLanguage(ToolStripMenuItem item)
        {

            DataRow dr = SystemAuthentication.UserMenu.Select("WinformId='" + item.Name + "'").FirstOrDefault();
            if(dr!=null)
                item.Text = dr["EngName"].ToString();
            foreach (ToolStripDropDownItem c in item.DropDownItems)
            {
                ToolStripMenuItem dropItem = c as ToolStripMenuItem;
                ToolStripItem dropItema = c as ToolStripItem;
                DataRow _dr = SystemAuthentication.UserMenu.Select("WinformId='" + dropItema.Name + "'").FirstOrDefault();
                if (_dr != null)
                    dropItem.Text = _dr["EngName"].ToString();
                ChangeEngLanguage(dropItem);
            }
        }
        private void barBtnCh_ItemClick(object sender ,ItemClickEventArgs e)
        {
            Loginer.CurrentUser.ChangeLanguage = 0;
            if (Lamex.Common.Loginer.CurrentUser.DBName == "Testing DataBase")
                Lamex.Common.Loginer.CurrentUser.DBName = "测试数据库";
            if (Lamex.Common.Loginer.CurrentUser.DBName == "Product DataBase")
                Lamex.Common.Loginer.CurrentUser.DBName = "正式数据库";
            this.Text = "美时MES系统";
            btnSetSkin.Caption = "皮肤 ";

            barHelp.Caption = "帮助";
            barBtnHelpDoc.Caption = "帮助文档";
            barBtnDevDoc.Caption = "开发说明";
            barBtnProjectManual.Caption = "项目手册";
            barBtnEvents.Caption = "大事记";
            barBtnAbout.Caption = "关于";

            barLanguageChange.Caption = "EN";
            //barLanguageChange.ImageOptions.Image = "";
            
            barSubEng.Caption = "";
            barSubCh.Caption = "中文";
            barSubEng.Caption = "英文";
            barSubRecordUse.Caption = "最近";
            barStaticDept.Caption = "部门：" + Lamex.Common.Loginer.CurrentUser.DeptName; 
            barStaticIUser.Caption = "用户：" + Lamex.Common.Loginer.CurrentUser.Account;
            barStaticEmail.Caption = "Email：" + Lamex.Common.Loginer.CurrentUser.Email;
            barStaticDb.Caption = "数据库：" + Lamex.Common.Loginer.CurrentUser.DBName;
            barStaticCopyRight.Caption = "© 东莞美时家具有限公司（HNI集团成员）版权所有";
            lookupEidt.NullValuePrompt = "菜单搜索";
            comboxEdit.NullValuePrompt = "菜单搜索";
            ini.IniWriteValue("Configuration", "ChangeLanguage", "0");
            
            //foreach (ToolStripMenuItem item in _moduleMenus.Items)
            //{
            //    ChangeChLanguage(item);
            //}
            //foreach (DevExpress.XtraBars.BarItem sub in barTools.Manager.Items)
            //{
            //    ToolStripMenuItem subitem = sub.Tag as ToolStripMenuItem;
            //    if (sub != null)
            //    {

            //        DataRow _dr = SystemAuthentication.UserMenu.Select("WinformId='" + sub.Name + "'").FirstOrDefault();
            //        if (_dr != null)
            //            sub.Caption = _dr["Name"].ToString();

            //    }
            //}
            _ModuleManager.ChangeChLanguages(barTools, _moduleMenus, navBarControl);
            ChangeTreeLanguage();

            foreach (XtraMdiTabPage Page in xtraTabbedMdiManager1.Pages)
            {
                Form f = Page.MdiChild;
                f.Text = f.Text + " ";
            }

        }
        private void barBtnEng_ItemClick(object sender, ItemClickEventArgs e)
        {
            Loginer.CurrentUser.ChangeLanguage = 1;
            if (Lamex.Common.Loginer.CurrentUser.DBName == "测试数据库")
                Lamex.Common.Loginer.CurrentUser.DBName = "Testing DataBase";
            if (Lamex.Common.Loginer.CurrentUser.DBName == "正式数据库")
                Lamex.Common.Loginer.CurrentUser.DBName = "Product DataBase";
            this.Text = "LAMEX MES SYSTEM";
            btnSetSkin.Caption = "SKIN";

            barHelp.Caption = "HELP";
            barBtnHelpDoc.Caption = "Help Document";
            barBtnDevDoc.Caption = "Develop Document";
            barBtnProjectManual.Caption = "Project Manual";
            barBtnEvents.Caption = "Events";
            barBtnAbout.Caption = "About";
            barSubRecordUse.Caption = "MostRecentlyUsed";
            barLanguageChange.Caption = "中文";
            barSubCh.Caption = "";
            barSubEng.Caption = "";
            barSubCh.Caption = "CHINESE";
            barSubEng.Caption = "ENGHLISH";

            barStaticDept.Caption = "Dept：" + Lamex.Common.Loginer.CurrentUser.DeptName; 
            barStaticIUser.Caption = "User：" + Lamex.Common.Loginer.CurrentUser.Account;
            barStaticEmail.Caption = "Email：" + Lamex.Common.Loginer.CurrentUser.Email;
            barStaticDb.Caption = "DataBase：" + Lamex.Common.Loginer.CurrentUser.DBName;
            barStaticCopyRight.Caption = "© 2019 Dongguan Lamex Furniture Co. Ltd. (Member HNI Corp). All Rights Reserved.";
            lookupEidt.NullValuePrompt = "Menu search";
            comboxEdit.NullValuePrompt = "Menu search";
            ini.IniWriteValue("Configuration", "ChangeLanguage", "1");
       
            //foreach (ToolStripMenuItem item in _moduleMenus.Items)
            //{
            //    ChangeEngLanguage(item); 
            //}
            //foreach (DevExpress.XtraBars.BarItem sub in barTools.Manager.Items)
            //{
            //    ToolStripMenuItem subitem = sub.Tag as ToolStripMenuItem;
            //    if (sub != null)
            //    {
            //        DataRow _dr = SystemAuthentication.UserMenu.Select("WinformId='" + sub.Name + "'").FirstOrDefault();
            //        if (_dr != null)
            //            sub.Caption = _dr["EngName"].ToString();

            //    }
            //}
            _ModuleManager.ChangeEngLanguages(barTools,_moduleMenus,navBarControl);
            ChangeTreeLanguage();
            base.InitChangeLanguage();
            foreach (XtraMdiTabPage Page in xtraTabbedMdiManager1.Pages)
            {
                Form f = Page.MdiChild;
                f.Text = f.Text+" ";
            }



            //frm.Paint += new PaintEventHandler(frm_Paint);
            //frm.Form_Load(null, null);
            //foreach (Control c in xtraTabbedMdiManager1.SelectedPage.MdiChild.Controls )
            //{

            //    if( c is )
            //    {
            //        frmBaseChild f = c as frmBaseChild;
            //        f.ChangeLanguage();
            //    }

            //}

            //xtraTabbedMdiManager1.SelectedPage.
            //_ModuleManager.CreateToolButtons(barTools, _moduleMenus);
        }
        private void frm_Paint(object sender,PaintEventArgs e)
        {

        }
        private void ChangeTreeLanguage()
        {
            navBarControl.Groups.Clear();
            navBarControl.Controls.Clear();
            
            
            foreach (ToolStripMenuItem item in _moduleMenus.Items)
            {
                //创建一级列表
                TreeView treeView = new TreeView();
                treeView.ImageList = imageList1;
                treeView.Dock = DockStyle.Fill;
                //treeView.ImageList = this.imageList;
                treeView.ItemHeight = 20;//设置高度，显示更美观
                treeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(treeView_MouseClick);
                treeView.AfterSelect += new TreeViewEventHandler(treeView_AfterSelect);

                NavBarGroupControlContainer container = new NavBarGroupControlContainer();

                container.Size = new System.Drawing.Size(213, 412);
                container.Controls.Add(treeView);
                navBarControl.Controls.Add(container);

                //加载图标
                //this.imageList.Images.Add(LoadIcon(firstInfo.Icon));
                //int index = this.imageList.Images.Count - 1;//最后一个序号

                NavBarGroup group = new NavBarGroup();
                group.Caption = item.Text;
                group.Name = item.Name;
                group.ControlContainer = container;
                group.Expanded = false;
                group.GroupClientHeight = 410;
                group.GroupStyle = NavBarGroupStyle.ControlContainer;
                //group.LargeImageIndex = index;
                //group.SmallImageIndex = index;
                navBarControl.Groups.Add(group);

                //创建一级列表
                TreeNode pNode = new TreeNode();
                pNode.ImageIndex = 0;
                pNode.Text = item.Text;
                pNode.Tag = item.Name;

                //pNode.ImageIndex = index;
                //pNode.SelectedImageIndex = index;
                treeView.Nodes.Add(pNode);

                EnumEachItem(item, pNode);
                treeView.ShowLines = true;



            }
        }
        private void barLanguageChange_ItemClick(object sender, ItemClickEventArgs e)
        {

            if (iLanguage == 0)
            {
                barBtnCh_ItemClick(null, null);
                iLanguage = 1;
            }
            else
            {
                barBtnEng_ItemClick(null, null);
                iLanguage = 0;
            }

        }

        private void barBtnHelpDoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            //ProcessStartInfo MyStarInfo = new ProcessStartInfo();
            //MyStarInfo.FileName = @"\\Tx-fs10\tx-fs1\LAMEX\MES\Documents\MES管理系统简介_20190712.pdf";
            ////窗口起始状态最大化
            //MyStarInfo.WindowStyle = ProcessWindowStyle.Maximized;
            //Process MyProcees = new Process();
            //MyProcees.StartInfo = MyStarInfo;
            //MyProcees.Start();

            frmMain_Help frm = new frmMain_Help();
            frm.ShowDialog();

        }

        private void barBtnDevDoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            //ProcessStartInfo MyStarInfo = new ProcessStartInfo();
            //MyStarInfo.FileName = @"\\Tx-fs10\tx-fs1\LAMEX\MES\Documents\MES系统开发说明.pdf";
            ////窗口起始状态最大化
            //MyStarInfo.WindowStyle = ProcessWindowStyle.Maximized;
            //Process MyProcees = new Process();
            //MyProcees.StartInfo = MyStarInfo;
            //MyProcees.Start();

            frmMain_DevDoc frm = new frmMain_DevDoc();
            frm.ShowDialog();
        }

        private void barBtnProjectManual_ItemClick(object sender, ItemClickEventArgs e)
        {
            //ProcessStartInfo MyStarInfo = new ProcessStartInfo();
            //MyStarInfo.FileName = @"\\Tx-fs10\tx-fs1\LAMEX\MES\Documents\MES项目管理系统操作手册.pdf";
            ////窗口起始状态最大化
            //MyStarInfo.WindowStyle = ProcessWindowStyle.Maximized;
            //Process MyProcees = new Process();
            //MyProcees.StartInfo = MyStarInfo;
            //MyProcees.Start();

            frmMain_ProjectManual frm = new frmMain_ProjectManual();
            frm.ShowDialog();
        }

        private void barBtnEvents_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmMain_EventsList frm = new frmMain_EventsList();
            frm.ShowDialog();
        }

        private void barBtnAbout_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmMain_About frm = new frmMain_About();
            frm.ShowDialog();
        }

        private void barStaticWebSite_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (iLanguage == 0)
            {
                System.Diagnostics.Process.Start("https://www.lamex.com/");
            }
            else
            {
                System.Diagnostics.Process.Start("https://www.lamex.com/zh-hans");
            } 
        }

        #region 鼠标滑过MES图标是显示相关信息或操作

        //AlertControl警示控件——如QQ右下角弹出消息提示，过一段时间消失
        //https://blog.csdn.net/archielau/article/details/37578327?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        private void pictureBox1_MouseHover(object sender, EventArgs e)
        {
            alertControl1.FormLocation = DevExpress.XtraBars.Alerter.AlertFormLocation.TopRight;//提出窗口的显示的位置
            alertControl1.AutoFormDelay = 500;//设置显示多少时间窗口会自动关闭
            //出现的效果方式
            alertControl1.FormShowingEffect = DevExpress.XtraBars.Alerter.AlertFormShowingEffect.FadeIn;
            //弹出的速度
            alertControl1.FormDisplaySpeed = DevExpress.XtraBars.Alerter.AlertFormDisplaySpeed.Slow;
            alertControl1.Show(this, "提示!", "感谢使用 MES系统!");
        }

        private void alertControl1_FormLoad(object sender, DevExpress.XtraBars.Alerter.AlertFormLoadEventArgs e)
        {
            //string strPath = System.Windows.Forms.Application.StartupPath;

            e.AlertForm.Size = new System.Drawing.Size(240, 120);

 
			// Show a sample alert window.
            //AlertInfo info = new AlertInfo("New Window", "Text");
            //alertControl1.Show(this, info);	
        }

        private void alertControl1_BeforeFormShow(object sender, DevExpress.XtraBars.Alerter.AlertFormEventArgs e)
        {
            //同FormLoad事件中大小的参数值一定要相同
            //e.AlertForm.Size = new System.Drawing.Size(300, 150);
            e.AlertForm.Size = new System.Drawing.Size(240, 120);
        }


		void alertControl1_ButtonClick(object sender, AlertButtonClickEventArgs e)
		{
            if (e.ButtonName == "buttonOpen")
            {
                MessageBox.Show("buttonOpen");
            }
        }

        void alertControl1_ButtonDownChanged(object sender, AlertButtonDownChangedEventArgs e)
        {
            if (e.ButtonName == "buttonAlert")
            {
                MessageBox.Show("buttonAlert");
            }
        }
 
        #endregion

        private void barSubRecordUse_ItemClick(object sender, ItemClickEventArgs e)
        {
            barSubRecordUse.ClearLinks();
            RecentlyUseRecord.LoadRecentlyRecordList(barSubRecordUse, _moduleMenus);
        }

    }

    //internal class ObserverCloseAllChild 
    //{
    //    private frmMainForm frmMainForm;

    //    public ObserverCloseAllChild(frmMainForm frmMainForm)
    //    {
    //        this.frmMainForm = frmMainForm;
    //    }
    //}
}
